import { SUBMIT,GET,INIT_SCHOOLS,INIT_NEWS } from "./actionTypes";
import axios from 'axios';

export const handleSubmitAction = (value) => ({
    type:SUBMIT,
    value
});
export const getUserNameAction = () =>({
    type:GET
});
export const InitSchoolsAction = (data) =>({
    type:INIT_SCHOOLS,
    data
});
export const InitNewsAction = (data) =>({
    type:INIT_NEWS,
    data
});
export const getSchoolsList = ()=> {
    return (dispatch) => {
         axios.get('/data.json').
            then((res) => {
                const data = res.data;
                const action = InitSchoolsAction(data);
                dispatch(action);
            }).
            catch(() => { alert('error') })
    }
};
export const getNewsList = ()=> {
    return (dispatch) => {
         axios.get('/data2.json').
            then((res) => {
                const data = res.data;
                const action = InitNewsAction(data);
                dispatch(action);
            }).
            catch(() => { alert('error') })
    }
};